#ifndef MONEY_H
#define MONEY_H

#include <QDate>
#include <QString>
#include <QObject>
#include "category.h"
#include <QDebug>

#define MONEY_DATE_FORMAT "dd/MM/yy"

class Money : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
    Q_PROPERTY(int moneyType READ moneyType WRITE setMoneyType NOTIFY moneyTypeChanged)
    Q_PROPERTY(float amount READ amount WRITE setAmount NOTIFY amountChanged)
    Q_PROPERTY(QString moneyDate READ moneyDate WRITE setMoneyDate NOTIFY moneyDateChanged)
    Q_PROPERTY(MoneyCategory* category READ category WRITE setCategory NOTIFY categoryChanged)
    Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
public:
    enum money_types {type_in, type_out, type_none};
signals:
    void idChanged();
    void moneyTypeChanged();
    void amountChanged();
    void moneyDateChanged();
    void categoryChanged();
    void descriptionChanged();
private:
    int idMoney;
    money_types type_money;
    float m_amount;
    QDate dtTransaction;
    QString m_description;
    QString timestamp;
    QList<MoneyCategory*> listMoneyCategory;
public:
    Money(QObject *parent = 0) : QObject(parent) { }

    int id() { return idMoney; }
    int moneyType() { return type_money; }
    float amount() { return m_amount; }
    QString moneyDate() { return dtTransaction.toString(MONEY_DATE_FORMAT);}
    MoneyCategory* category()
    {
        if (listMoneyCategory.length() > 0)
            return listMoneyCategory.at(0);
        return 0;
    }
    QString description() { return m_description; }

    void setId(int id) { idMoney = id; }
    void setMoneyType(int type) { type_money = type == 0 ? type_in : type_out; }
    void setMoneyDate(QString strDate)
    {
        qDebug() << strDate;
        dtTransaction = QDate::fromString(strDate, MONEY_DATE_FORMAT);
        dtTransaction = dtTransaction.addYears(100);
        qDebug() << dtTransaction;
    }
    void setCategory(MoneyCategory* category)
    {
        // Despite the real implementation, this method consider only a category by Money Register
        listMoneyCategory.clear();
        listMoneyCategory.append(category);
    }

    void setIdMoney(int idMoney) { this->idMoney = idMoney;}
    void setTypeMoney(money_types type_money) { this->type_money = type_money; }
    void setAmount(float amount) { this->m_amount = amount;}
    void setDtTransaction(QDate dtTransaction) { this->dtTransaction = dtTransaction;}
    void setDescription(QString description) { this->m_description = description;}
    void setListMoneyCategory(QList<MoneyCategory*> listMoneyCategory) { this->listMoneyCategory = listMoneyCategory;}
    void setTimestamp(QString timestamp) { this->timestamp = timestamp; }

    int getIdMoney() { return idMoney; }
    money_types getTypeMoney() { return type_money; }
    float getAmount() { return m_amount; }
    QDate getDtTransaction() { return dtTransaction; }
    QString getDescription() { return m_description; }
    QList<MoneyCategory*> getListMoneyCategory() { return listMoneyCategory; }
    QString getTimestamp() { return timestamp; }

};

#endif // MONEY_H
